package com.beagle.njddapp.ui.fragment;

import android.content.Intent;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.amap.api.location.AMapLocation;
import com.amap.api.maps.AMap;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.LocationSource;
import com.amap.api.maps.MapView;
import com.amap.api.maps.TextureMapView;
import com.amap.api.maps.UiSettings;
import com.amap.api.maps.model.BitmapDescriptor;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.Marker;
import com.amap.api.maps.model.MarkerOptions;
import com.amap.api.maps.model.MyLocationStyle;
import com.amap.api.services.core.AMapException;
import com.amap.api.services.core.LatLonPoint;
import com.amap.api.services.core.PoiItem;
import com.amap.api.services.route.BusRouteResult;
import com.amap.api.services.route.DrivePath;
import com.amap.api.services.route.DriveRouteResult;
import com.amap.api.services.route.RideRouteResult;
import com.amap.api.services.route.RouteSearch;
import com.amap.api.services.route.WalkRouteResult;
import com.beagle.njddapp.R;
import com.beagle.njddapp.base.ApiService;
import com.beagle.njddapp.base.DirverApiService;
import com.beagle.njddapp.base.NjOwnerApiService;
import com.beagle.njddapp.base.RetrofitHttp;
import com.beagle.njddapp.bean.dirver.OilOrderState;
import com.beagle.njddapp.bean.owner.DIrverOrderBean;
import com.beagle.njddapp.bean.owner.NjBean;
import com.beagle.njddapp.core.LocationManager;
import com.beagle.njddapp.core.UserService;
import com.beagle.njddapp.net.BaseOilHttpListResponse;
import com.beagle.njddapp.net.BaseOilHttpResponse;
import com.beagle.njddapp.net.BaseStringResponseBean;
import com.beagle.njddapp.net.HttpResponseObserver;
import com.beagle.njddapp.net.RxSchedulers;
import com.beagle.njddapp.ui.activity.ChooseAeraActivity;
import com.beagle.njddapp.ui.activity.NewStartActivity;
import com.beagle.njddapp.utils.map.AMapUtil;
import com.beagle.njddapp.utils.map.DrivingRouteOverlay;
import com.beagle.njddapp.weight.dialog.DIrverDIalog;
import com.beagle.njddapp.weight.dialog.JiayouDIalog;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.google.gson.Gson;

import java.util.HashMap;
import java.util.LinkedHashMap;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import okhttp3.RequestBody;

/**
 * @author hxx
 * @date 2021-03-13 19:12
 */
public class CommonMapfragment extends Fragment implements LocationSource, LocationManager.LocationChangeLisenter, RouteSearch.OnRouteSearchListener, AMap.OnMarkerClickListener, DIrverDIalog.DirverJiaYouCallBack, JiayouDIalog.JiaYouDialogHandleCallback, AMap.OnMapLoadedListener {

    @BindView(R.id.map)
    TextureMapView mMapView;
    private AMap aMap;
    @BindView(R.id.prograssBar)
    ProgressBar progressBar;
    MyLocationStyle myLocationStyle;
    private OnLocationChangedListener mListener;
    private UiSettings mUiSettings;
    private Marker maker;
    private double longitude = -22222, latitude = -22222;
    private double endLongitude = -22222, endLatitude = -22222;
    private int type;
    private boolean isFirstLocation;//是否第一次获取到位置
    private RouteSearch routeSearch;
    private LatLonPoint mStartPoint;
    private LatLonPoint mEndPoint;
    private DriveRouteResult mDriveRouteResult;
    private OilOrderState oilOrderState;
    private DIrverOrderBean dIrverOrderBean;
    private DIrverDIalog dIrverDIalog;
    private JiayouDIalog jiayouDIalog;
    private DirverApiService dirverApiService;
    private ApiService apiService;
    private PoiItem currentPos;
    private boolean isnow;//是否选择当前点位


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LocationManager.getInstance().addLisenter(this);
        Bundle bundle = getArguments();
        if (bundle != null) {
            endLatitude = bundle.getDouble("latitude");
            endLongitude = bundle.getDouble("longitude");
            type = bundle.getInt("type", -1);
            oilOrderState = (OilOrderState) bundle.getSerializable("oilOrderState");
            dIrverOrderBean = (DIrverOrderBean) bundle.getSerializable("dIrverOrderBean");
        }

    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(getLayoutId(), null);
        ButterKnife.bind(this, view);
        mMapView.onCreate(savedInstanceState);
        return view;
    }

    public int getLayoutId() {
        return R.layout.fragment_map;
    }

    @Override
    public void onResume() {
        super.onResume();
        mMapView.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
        mMapView.onPause();
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        mMapView.onSaveInstanceState(outState);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        aMap = mMapView.getMap();
        mUiSettings = aMap.getUiSettings();
        aMap.setOnMapLoadedListener(this);
        //设置地图的放缩级别
        aMap.moveCamera(CameraUpdateFactory.zoomTo(15));
        aMap.setLocationSource(this);
        mUiSettings.setZoomControlsEnabled(false);
        aMap.setMyLocationEnabled(true);// 设置为true表示启动显示定位蓝点，false表示隐藏定位蓝点并不进行定位，默认是false
        myLocationStyle = new MyLocationStyle();//初始化定位蓝点样式类myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE);//连续定位、且将视角移动到地图中心点，定位点依照设备方向旋转，并且会跟随设备移动。（1秒1次定位）如果不设置myLocationType，默认也会执行此种模式。
        myLocationStyle.interval(2000); //设置连续定位模式下的定位间隔，只在连续定位模式下生效，单次定位模式下不会生效。单位为毫秒。
        myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE);//连续定位、且将视角移动到地图中心点，定位点依照设备方向旋转，并且会跟随设备移动。（1秒1次定位）默认执行此种模式。
        myLocationStyle.showMyLocation(true);
        myLocationStyle.strokeColor(Color.TRANSPARENT);
        myLocationStyle.radiusFillColor(Color.TRANSPARENT);
        if (type == 1) {
            aMap.setOnMapClickListener(new AMap.OnMapClickListener() {
                @Override
                public void onMapClick(LatLng latLng) {
                    if (getActivity() != null && getActivity() instanceof NewStartActivity) {
                        ((NewStartActivity) getActivity()).mapToMain();
                    }
                }
            });
        } else if (type != 2) {
            if (UserService.getInstance().getRole() == UserService.ROLE_OIL) {
                BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(getResources(), R.mipmap.maps_ic_gastanker));
                myLocationStyle.myLocationIcon(bitmapDescriptor);
            } else {
                BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(getResources(), R.mipmap.maps_ic_car));
                myLocationStyle.myLocationIcon(bitmapDescriptor);
            }
        }
        aMap.getUiSettings().setMyLocationButtonEnabled(true);// 设置默认定位按钮是否显示
        aMap.setMyLocationStyle(myLocationStyle);//设置定位蓝点的Style
        routeSearch = new RouteSearch(getContext());
        routeSearch.setRouteSearchListener(this);

//        aMap.setOnMarkerClickListener(this);

    }

    private void addMarker() {
//        LogUtils.d("addMarker longitude: "+longitude+",latitude:"+latitude);
        MarkerOptions markerOption = new MarkerOptions();
        LatLng latLng = new LatLng(endLatitude, endLongitude, false);
        markerOption.position(latLng);
        markerOption.visible(true);
        markerOption.draggable(false);//设置Marker可拖动
        markerOption.setFlat(true);
        if (UserService.getInstance().getRole() == UserService.ROLE_OIL) {
            BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(getResources(), R.mipmap.maps_ic_car));
            markerOption.icon(bitmapDescriptor);
        } else {
            BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(getResources(), R.mipmap.maps_ic_gastanker));
            markerOption.icon(bitmapDescriptor);
        }
        // 将Marker设置为贴地显示，可以双指下拉地图查看效果
        maker = aMap.addMarker(markerOption);
        mStartPoint = new LatLonPoint(latitude, longitude);//起点，39.942295,116.335891
        mEndPoint = new LatLonPoint(endLatitude, endLongitude);
        RouteSearch.DriveRouteQuery query = new RouteSearch.DriveRouteQuery(new RouteSearch.FromAndTo(mStartPoint, mEndPoint), RouteSearch.DrivingDefault, null, null, "");
        routeSearch.calculateDriveRouteAsyn(query);

    }


    private void addMyMarker() {
//        LogUtils.d("addMarker longitude: "+longitude+",latitude:"+latitude);
        MarkerOptions markerOption = new MarkerOptions();
        LatLng latLng = new LatLng(latitude, longitude, false);
        markerOption.position(latLng);
        markerOption.visible(true);
        markerOption.draggable(false);//设置Marker可拖动
        markerOption.setFlat(true);
        if (UserService.getInstance().getRole() == UserService.ROLE_OIL) {
            BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(getResources(), R.mipmap.maps_ic_gastanker));
            markerOption.icon(bitmapDescriptor);
        } else {
            BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(getResources(), R.mipmap.maps_ic_car));
            markerOption.icon(bitmapDescriptor);
        }
        // 将Marker设置为贴地显示，可以双指下拉地图查看效果
        maker = aMap.addMarker(markerOption);
        aMap.addOnMarkerClickListener(this);
//        mStartPoint = new LatLonPoint(latitude, longitude);//起点，39.942295,116.335891
//        mEndPoint = new LatLonPoint(endLatitude, endLongitude);
//        RouteSearch.DriveRouteQuery query = new RouteSearch.DriveRouteQuery(new RouteSearch.FromAndTo(mStartPoint,mEndPoint), RouteSearch.DrivingDefault, null, null, "");
//        routeSearch.calculateDriveRouteAsyn(query);

    }


    @Override
    public void onDestroy() {
        super.onDestroy();
        if (mMapView != null) {
            mMapView.onDestroy();
        }
    }

    @Override
    public void activate(OnLocationChangedListener onLocationChangedListener) {
        mListener = onLocationChangedListener;
        mListener.onLocationChanged(LocationManager.getInstance().location);
    }

    @Override
    public void deactivate() {
        mListener = null;
    }

    @Override
    public void onLocationChanged(AMapLocation location) {
        LogUtils.d("(" + longitude + "," + latitude + "),( " + location.getLongitude() + "," + location.getLatitude() + ")");
        if (longitude != location.getLongitude() || latitude != location.getLatitude()) {
            longitude = location.getLongitude();
            latitude = location.getLatitude();
            mListener.onLocationChanged(location);
            if (isFirstLocation) {
                return;
            }
            isFirstLocation = true;
            if (type == 2) {
                //驾驶员首页
                if (oilOrderState.getLastOilRequest() == null) {
                    //无订单
                    addMyMarker();
                } else {
                    //有订单
                    addMyMarker();
                    addMarker();
                }
            } else {
                if (longitude != -22222 && latitude != -22222) {
                    if (type == 1) {
                        addMyMarker();
                    } else {
                        addMarker();
                    }

                }
            }

        }
    }


    @Override
    public void onBusRouteSearched(BusRouteResult busRouteResult, int i) {

    }

    @Override
    public void onDriveRouteSearched(DriveRouteResult result, int errorCode) {
        LogUtils.d("onDriveRouteSearched :" + errorCode);
        if (errorCode == AMapException.CODE_AMAP_SUCCESS) {
            if (result != null && result.getPaths() != null) {
                if (result.getPaths().size() > 0) {
                    mDriveRouteResult = result;
                    final DrivePath drivePath = mDriveRouteResult.getPaths()
                            .get(0);
                    if (drivePath == null) {
                        return;
                    }
                    DrivingRouteOverlay drivingRouteOverlay = new DrivingRouteOverlay(
                            getContext(), aMap, drivePath,
                            mDriveRouteResult.getStartPos(),
                            mDriveRouteResult.getTargetPos(), null);
                    drivingRouteOverlay.setNodeIconVisibility(false);//设置节点marker是否显示
                    drivingRouteOverlay.setIsColorfulline(true);//是否用颜色展示交通拥堵情况，默认true
                    drivingRouteOverlay.removeFromMap();
                    drivingRouteOverlay.addToMap();
                    drivingRouteOverlay.zoomToSpan();
//                    mBottomLayout.setVisibility(View.VISIBLE);
                    int dis = (int) drivePath.getDistance();
                    int dur = (int) drivePath.getDuration();
                    String des = AMapUtil.getFriendlyTime(dur) + "(" + AMapUtil.getFriendlyLength(dis) + ")";
//                    mRotueTimeDes.setText(des);
//                    mRouteDetailDes.setVisibility(View.VISIBLE);
//                    int taxiCost = (int) mDriveRouteResult.getTaxiCost();
//                    mRouteDetailDes.setText("打车约"+taxiCost+"元");
//                    mBottomLayout.setOnClickListener(new View.OnClickListener() {
//                        @Override
//                        public void onClick(View v) {
//                            Intent intent = new Intent(mContext,
//                                    DriveRouteDetailActivity.class);
//                            intent.putExtra("drive_path", drivePath);
//                            intent.putExtra("drive_result",
//                                    mDriveRouteResult);
//                            startActivity(intent);
//                        }
//                    });

                } else if (result != null && result.getPaths() == null) {
//                    ToastUtil.show(mContext, R.string.no_result);
                }

            } else {
//                ToastUtil.show(mContext, R.string.no_result);
            }
        } else {
//            ToastUtil.showerror(this.getApplicationContext(), errorCode);
        }
    }

    @Override
    public void onWalkRouteSearched(WalkRouteResult walkRouteResult, int i) {

    }

    @Override
    public void onRideRouteSearched(RideRouteResult rideRouteResult, int i) {

    }

    @Override
    public boolean onMarkerClick(Marker marker) {
        if (type == 2) {
            if (dIrverOrderBean != null) {
                getList();

            }
        }
        return true;
    }

    public void getList() {
        retrofit2.Retrofit retrofit = RetrofitHttp.provideRetrofit();
        NjOwnerApiService njOwnerApiService = retrofit.create(NjOwnerApiService.class);
        Gson gson = new Gson();
        HashMap<String, String> paramsMap = new LinkedHashMap<>();
        paramsMap.put("orderId", "");
        paramsMap.put("orderNum", "");
        paramsMap.put("orderStatus", "");
        String strEntity = gson.toJson(paramsMap);
        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json;charset=UTF-8"), strEntity);
        paramsMap.clear();
        njOwnerApiService.queryFindDriverOrderList(1000+"",1+"",body).compose(RxSchedulers.compose()).safeSubscribe(new HttpResponseObserver<BaseOilHttpListResponse<DIrverOrderBean>>() {
            @Override
            public void success(BaseOilHttpListResponse<DIrverOrderBean> orderBeanBaseOilHttpListResponse) {
                if (orderBeanBaseOilHttpListResponse!=null&&orderBeanBaseOilHttpListResponse.results!=null){
                    if (orderBeanBaseOilHttpListResponse.results.size()>0){
                        for (DIrverOrderBean orderBean:orderBeanBaseOilHttpListResponse.results){
                            if (orderBean.getOrderStatus()==6){
                                continue;
                            }
                            dIrverOrderBean=orderBean;
                            break;
                        }
                        getMeshData(dIrverOrderBean);

                    }
                }
            }
            @Override
            public void error(int code, String message) {
            }
        });
    }

    private void getMeshData(DIrverOrderBean dIrverOrderBean) {
        retrofit2.Retrofit retrofit = RetrofitHttp.provideRetrofit();
        DirverApiService dirverApiService = retrofit.create(DirverApiService.class);
        Gson gson = new Gson();
        String strEntity = gson.toJson(dIrverOrderBean);
        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json;charset=UTF-8"), strEntity);
        dirverApiService.meshState(body).compose(RxSchedulers.compose()).safeSubscribe(new Observer<OilOrderState>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(OilOrderState o) {
                if (o == null) {
                    return;
                }
                oilOrderState = o;
                if (dIrverDIalog == null) {
                    dIrverDIalog = new DIrverDIalog(getContext());
                    dIrverDIalog.setDirverJiaYouCallBack(CommonMapfragment.this);
                }
                dIrverDIalog.show();
                dIrverDIalog.update(dIrverOrderBean, oilOrderState);

            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onComplete() {

            }
        });
    }

    @Override
    public void jiayou() {
        if (jiayouDIalog == null) {
            jiayouDIalog = new JiayouDIalog(getContext());
            jiayouDIalog.setJiaYouDialogHandleCallback(this);
        }
        jiayouDIalog.show();
        jiayouDIalog.dirverUpdate();
    }

    @Override
    public void tz(String reason, int id, String time) {
        progressBar.setVisibility(View.VISIBLE);
        if (dirverApiService == null) {
            retrofit2.Retrofit retrofit = RetrofitHttp.provideRetrofit();
            dirverApiService = retrofit.create(DirverApiService.class);
            apiService = retrofit.create(ApiService.class);
        }
        Gson gson = new Gson();
        HashMap<String, String> paramsMap = new LinkedHashMap<>();
        paramsMap.put("reason", reason);
        paramsMap.put("orderId", id + "");
        paramsMap.put("endDate", time);
        String strEntity = gson.toJson(paramsMap);
        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json;charset=UTF-8"), strEntity);
        dirverApiService.updateFindDriverOrderDate(body).compose(RxSchedulers.compose()).safeSubscribe(new HttpResponseObserver<BaseOilHttpResponse>() {


            @Override
            public void success(BaseOilHttpResponse baseOilHttpResponse) {
                ToastUtils.showShort("调整申请已发送给农机主");
                progressBar.setVisibility(View.GONE);
            }

            @Override
            public void error(int code, String message) {
                ToastUtils.showShort("服务异常");
                progressBar.setVisibility(View.GONE);
            }

        });
    }

    @Override
    public void giveBack(int id) {
        progressBar.setVisibility(View.VISIBLE);
        if (dirverApiService == null) {
            retrofit2.Retrofit retrofit = RetrofitHttp.provideRetrofit();
            dirverApiService = retrofit.create(DirverApiService.class);
            apiService = retrofit.create(ApiService.class);
        }
        Gson gson = new Gson();
        HashMap<String, String> paramsMap = new LinkedHashMap<>();
        paramsMap.put("orderId", id + "");
        String strEntity = gson.toJson(paramsMap);
        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json;charset=UTF-8"), strEntity);
        paramsMap.clear();
        dirverApiService.deviceGiveBack(body).compose(RxSchedulers.compose()).safeSubscribe(new Observer<BaseOilHttpResponse>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(BaseOilHttpResponse o) {
                ToastUtils.showShort("归还成功，等待农机主确认");
                progressBar.setVisibility(View.GONE);
            }

            @Override
            public void onError(Throwable e) {
                ToastUtils.showShort("服务异常");
                progressBar.setVisibility(View.GONE);
            }

            @Override
            public void onComplete() {

            }
        });

    }

    @Override
    public void JiaYouOk(NjBean njBean, String phone, String address, String count) {
        if (dirverApiService == null) {
            retrofit2.Retrofit retrofit = RetrofitHttp.provideRetrofit();
            dirverApiService = retrofit.create(DirverApiService.class);
            apiService = retrofit.create(ApiService.class);
        }
        progressBar.setVisibility(View.VISIBLE);
        Gson gson = new Gson();
        HashMap<String, String> paramsMap = new LinkedHashMap<>();
        paramsMap.put("type", "fuelRequest");
        String strEntity = gson.toJson(paramsMap);
        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json;charset=UTF-8"), strEntity);
        paramsMap.clear();
        apiService.requestFormToken(body).compose(RxSchedulers.compose()).safeSubscribe(new Observer<BaseStringResponseBean>() {
            @Override
            public void onSubscribe(Disposable d) {

            }
            @Override
            public void onNext(BaseStringResponseBean baseStringResponseBean) {
                if (baseStringResponseBean.getResult() != null) {
                    Gson gson = new Gson();
                    HashMap<String, String> paramsMap = new HashMap<>();
                    paramsMap.put("meshId", dIrverOrderBean.getMeshId() + "");
                    paramsMap.put("latitude",currentPos==null? LocationManager.getInstance().getLatitude()+"":currentPos.getLatLonPoint().getLatitude()+"");
                    paramsMap.put("longitude",currentPos==null?LocationManager.getInstance().getLongitude()+"":currentPos.getLatLonPoint().getLongitude()+"");
                    paramsMap.put("address", address);
                    paramsMap.put("expectMeter", count);
                    paramsMap.put("formToken", baseStringResponseBean.getResult());
                    String strEntity = gson.toJson(paramsMap);
                    RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json;charset=UTF-8"), strEntity);
                    dirverApiService.createRequest(body).compose(RxSchedulers.compose()).safeSubscribe(new HttpResponseObserver<BaseOilHttpResponse>() {
                        @Override
                        public void success(BaseOilHttpResponse o) {
                            ToastUtils.showShort("申请加油成功");
                            progressBar.setVisibility(View.GONE);
                        }

                        @Override
                        public void error(int code, String message) {
                            ToastUtils.showShort(message);
                            progressBar.setVisibility(View.GONE);
                        }
                    });
                }
            }

            @Override
            public void onError(Throwable e) {
                ToastUtils.showShort("服务异常");
                progressBar.setVisibility(View.GONE);

            }

            @Override
            public void onComplete() {

            }


        });
    }

    @Override
    public void chooseAera() {
        startActivityForResult(new Intent(getContext(), ChooseAeraActivity.class),102);

    }
    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode==144&&data!=null){
            PoiItem poiItem=data.getParcelableExtra("pos");
            if (poiItem!=null){
                currentPos=poiItem;
                if (jiayouDIalog!=null&&jiayouDIalog.isShowing()){
                    jiayouDIalog.dirverUpdate(poiItem);
                }
            }
        } else if (resultCode==244&&data!=null){
            isnow=data.getBooleanExtra("loc",false);
            if (isnow){
                if (jiayouDIalog!=null&&jiayouDIalog.isShowing()){
                    jiayouDIalog.dirverUpdateLocation();
                }
            }
        }
    }

    @Override
    public void onMapLoaded() {
        aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(LocationManager.getInstance().getLatitude(), LocationManager.getInstance().getLongitude()), 15));
    }
}
